package com.neusoft.neuiotms.dcom.repository.change.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.change.ChangeImplementation;
import com.neusoft.neuiotms.dcom.model.change.QChangeImplementation;
import com.neusoft.neuiotms.dcom.repository.change.CustomizedChangeImplementationRepository;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedChangeImplementationRepositoryImpl extends AbstractRepository
        implements CustomizedChangeImplementationRepository {

    @Override
    protected Class<?> getModelClass() {
        return ChangeImplementation.class;
    }

    @Override
    public ChangeImplementation findByWorkNum(final String workOrderNum) {
        final QChangeImplementation qChangeImplementation = QChangeImplementation.changeImplementation;
        final JPAQuery<ChangeImplementation> query = this.query().selectFrom(qChangeImplementation);
        query.where(qChangeImplementation.workOrderNum.eq(workOrderNum))
                .orderBy(qChangeImplementation.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
